package com.teaphy.coroutinecrawler.flow

import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.runBlocking

fun main() = runBlocking {

    println("runBlocking - thread：${Thread.currentThread().name}")

    var num = 0

    val flow: Flow<Int> = flow<Int> {
        println("flow emmit - thread：${Thread.currentThread().name}")
        while (num < 5) {
            println("发送数据：$num")
            emit(num)
            delay(1000)
            num++
        }

    }

    flow.collect {
        println("flow collect - thread：${Thread.currentThread().name}")
        println("接收数据: $it")
    }

    print("Done")
}

